package com.jinjie.reids;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import redis.clients.jedis.JedisCluster;

import javax.annotation.Resource;
import java.util.Set;

/**
 * @author lisw
 * @program ddp-project
 * @description Redis管理器 集群模式
 * @createDate 2022-11-01 17:19:29
 **/
@Component
@ConditionalOnProperty(value = "redis.model",havingValue = "cluster",matchIfMissing = false)
@Slf4j
public class RedisManagerJedisCluster implements BaseRedisManager {

    private int expire = 0;

    @Resource
    private JedisCluster jedisCluster;

    @Override
    public byte[] get(byte[] key) {
       return jedisCluster.get(key);
    }

    @Override
    public String get(String key) {
       return jedisCluster.get(key);
    }

    @Override
    public byte[] set(byte[] key, byte[] value) {
       jedisCluster.set(key,value);
       if(this.expire!=0){
           jedisCluster.expire(key,expire);
       }
      return value;
    }

    @Override
    public String set(String key, String value) {
        jedisCluster.set(key,value);
        if(this.expire!=0){
            jedisCluster.expire(key,expire);
        }
        return value;
    }

    @Override
    public byte[] set(byte[] key, byte[] value, int expire) {
        jedisCluster.set(key,value);
        if(expire!=0){
            jedisCluster.expire(key,expire);
        }
        return value;
    }

    @Override
    public String set(String key, String value, int expire) {
        jedisCluster.set(key,value);
        if(expire!=0){
            jedisCluster.expire(key,expire);
        }
        return value;
    }

    @Override
    public void del(byte[] key) {
        jedisCluster.del(key);
    }

    @Override
    public Long dbSize(byte[] bytes) {
        return null;
    }

    @Override
    public Set<byte[]> keys(byte[] bytes) {
        return null;
    }

    @Override
    public void del(String key) {
        jedisCluster.del(key);
    }
}
